package com.kun.dao.impl;


import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.kun.dao.LoginDao;
import com.kun.entity.CustomerEntity;
@Repository("LoginDaoImpl")
public class LoginDaoImpl implements LoginDao {

	public List<CustomerEntity> login(String hql,CustomerEntity customerEntity) {
		ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
		SessionFactory sf = (SessionFactory) app.getBean("sessionFactory");
		Session session = sf.openSession();
		Query query = session.createQuery(hql);
		query.setString(0,customerEntity.getCustomerName());
		query.setString(1,customerEntity.getCustomerPass());
		List<CustomerEntity> list = query.list();
		
		return list;

	}
	
	public String selPhoneById(String hql, int id) {
		ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
		SessionFactory sf = (SessionFactory) app.getBean("sessionFactory");
		Session session = sf.openSession();
		Query query = session.createQuery(hql);
		query.setInteger(0,id);
		List<CustomerEntity> list = query.list();
		if(list.size() > 0){
			return list.get(0).getCustomerPhone();
		}else{
			return "请输入电话号码";
		}
	}



}
